Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

content: Support the new class of channel wildcard mentions #1073

Merged
merged 1 commit into from
Dec 5, 2024

Conversation

sm-sayedi
Copy link
Collaborator

For channel wildcard mentions, the class in the corresponding HTML used to be the same as the user mentions (class="user-mention"), but now there's an additional class added. Now it looks like the following: class="user-mention channel-wildcard-mention".

Fixes: #1064

@sm-sayedi sm-sayedi added the maintainer review PR ready for review by Zulip maintainers label Nov 22, 2024
@gnprice gnprice requested a review from PIG208 November 25, 2024 21:45
@PIG208 PIG208 self-assigned this Nov 25, 2024
Copy link
Member

@PIG208 PIG208 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This looks good. Left some comments.

Comment on lines 814 to 816
const mentionClass = r"user(?:-group)?-mention|"
"(?:user-mention channel-wildcard-mention)";
return RegExp("^(?:$mentionClass)(?: silent)?|silent (?:$mentionClass)\$");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the non-capturing groups added here are not necessary:

Suggested change
const mentionClass = r"user(?:-group)?-mention|"
"(?:user-mention channel-wildcard-mention)";
return RegExp("^(?:$mentionClass)(?: silent)?|silent (?:$mentionClass)\$");
const mentionClass = r"user(?:-group)?-mention|"
"user-mention channel-wildcard-mention";
return RegExp("^(?:$mentionClass)(?: silent)?|silent $mentionClass\$");

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing this I wondered if regular expressions are the right tool for this issue, but then I read from the commit message of 4a10b3c mentioning that this is more efficient than classes. Makes sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The groups around mentionClass are needed. The revised version above would have a three-way alternative: either ^(?:$mentionClass)(?: silent)?, or silent user(?:-group)?-mention, or user-mention channel-wildcard-mention$.

Probably the cleanest way to express that is by mentionClass itself containing the (?: and ).

In main there's also a group enclosing everything between ^ and $. That's necessary so that ^ and $ apply to all alternatives, instead of just the first and last of them respectively.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just sent #1086 to refactor the existing logic here, reducing the role of the regexp and hopefully making it easier to add more features. @sm-sayedi PTAL and try rebasing your work atop that.

@sm-sayedi sm-sayedi force-pushed the 1064-channel-wildcard-mentions branch 2 times, most recently from 20c3911 to 79b117d Compare November 27, 2024 05:09
@sm-sayedi
Copy link
Collaborator Author

Thanks @PIG208 and @gnprice for the previous comments. Pushed the new changes with the branch being rebased on top of #1086. PTAL.

bool isChannelWildcardClassIncluded = false;
if (classes[i] == 'channel-wildcard-mention') {
// A newly-added class for channel wildcard mentions.
// See: https://github.com/zulip/zulip/pull/31075
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example is contained in our tests, so we can probably cut this comment. And the context of "newly-added" might fit better in the commit message.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PIG208 PIG208 added integration review Added by maintainers when PR may be ready for integration and removed maintainer review PR ready for review by Zulip maintainers labels Dec 3, 2024
@PIG208 PIG208 requested a review from gnprice December 3, 2024 20:27
Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sm-sayedi for taking care of this, and @PIG208 for the previous reviews! This all looks good; some nits below.

int i = 0;

if (i >= classes.length) return null;
bool isChannelWildcardClassIncluded = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can simplify "is X included" to "has X":

Suggested change
bool isChannelWildcardClassIncluded = false;
bool hasChannelWildcardClass = false;

Comment on lines 885 to 887
if (classes[i] == 'channel-wildcard-mention') {
// A newly-added class for channel wildcard mentions.
// See: https://github.com/zulip/zulip/pull/31075
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a comment is useful here, because there is certain information it can convey that's relevant for the reader trying to understand this function. Here's a version focused on that information:

Suggested change
if (classes[i] == 'channel-wildcard-mention') {
// A newly-added class for channel wildcard mentions.
// See: https://github.com/zulip/zulip/pull/31075
if (classes[i] == 'channel-wildcard-mention') {
// Newer channel wildcard mentions have this class; older ones don't.

In particular, in my other review comment above I almost suggested naming the variable isChannelWildcard — before I remembered that that would be an inaccurate name, because some genuine channel wildcards don't have this class. That fact will be highly relevant when someone goes to implement #646, as it'd otherwise be tempting to use this class for doing so.

Comment on lines 899 to 900
if (classes[i] == 'user-mention' ||
(classes[i] == 'user-group-mention' && !isChannelWildcardClassIncluded)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: indentation; and operators go after newline:

Suggested change
if (classes[i] == 'user-mention' ||
(classes[i] == 'user-group-mention' && !isChannelWildcardClassIncluded)) {
if (classes[i] == 'user-mention'
|| (classes[i] == 'user-group-mention' && !isChannelWildcardClassIncluded)) {

(See examples in parseInlineContent below.)

With less indentation, the second sub-condition looks like it's a peer of the if condition as a whole.

For the rationale for || after newline, see:
https://github.com/zulip/zulip-mobile/blob/a115df1f71c9dc31e9b41060a8d57b51c017d786/tools/formatting.eslintrc.yaml#L20-L23

@@ -1213,7 +1255,13 @@ void main() {
testParseExample(ContentExample.groupMentionSilent);
testParseExample(ContentExample.groupMentionSilentClassOrderReversed);

// TODO test wildcard mentions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, good to have this handled 🙂

'<p><span class="silent user-mention channel-wildcard-mention" data-user-id="*">channel</span></p>',
const UserMentionNode(nodes: [TextNode('channel')]));

static final legacyChannelWildcardMentionPlain = ContentExample.inline(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this naming is good: the current/new way gets the simple name, and the old way gets the longer "legacy" name.

@sm-sayedi sm-sayedi force-pushed the 1064-channel-wildcard-mentions branch from 79b117d to 9c3d023 Compare December 4, 2024 05:41
@sm-sayedi
Copy link
Collaborator Author

sm-sayedi commented Dec 4, 2024

Thanks @gnprice and @PIG208 for the reviews! Changes pushed.

Edit: CI failed for some reason; I will look at it and fix it!

New edit: CI failure is fixed now!

@sm-sayedi sm-sayedi force-pushed the 1064-channel-wildcard-mentions branch 2 times, most recently from 29e0154 to 698a93b Compare December 5, 2024 02:29
Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the revision! Looks good, with one nit below. I'll fix that and merge.

Comment on lines 885 to 893
// A silent @-mention. We ignore this flag; see [UserMentionNode].
// A silent @-mention. We ignore this flag; see [UserMentionNode].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extraneous change

For channel wildcard mentions, the class in the corresponding HTML used
to be the same as the user mentions (class="user-mention"), but now
there's an additional class added. Now it looks like the following:
class="user-mention channel-wildcard-mention".

Fixes: zulip#1064
@gnprice gnprice force-pushed the 1064-channel-wildcard-mentions branch from 698a93b to fb6291f Compare December 5, 2024 04:09
@gnprice gnprice merged commit fb6291f into zulip:main Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration review Added by maintainers when PR may be ready for integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New channel wildcard mentions are rendered as "unimplemented"
3 participants